<?php namespace Home\Controller;
use Hdphp\Libs\Controller;
class LoginController extends Controller
{
	//登陆
	public function login()
	{
		if(IS_POST)
		{
			$username = $_POST['username'];
			$password = md5($_POST['password']);
			$code = $_POST['code'];
			p($_SESSION['code']);
			//判断用户名是否正确
			$data = M()->query("select * from c_five_seven where username='{$username}'");
			//走到这里是用户名在数据库中不存在
			if(!$data)$this->error("用户名错误");
			
			//判断密码是否正确
			//走到这一步说明用户名正确
			if($password != $data[0]['password']) $this->error("密码错误");
			//判断验证码
			if(strtoupper($_SESSION['code']) != strtoupper($code)) $this->error("验证码错误");
			
			$_SESSION['username']=$username;
			$_SESSION['uid']=$data[0]['uid'];
			$this->success("登陆成功", "index.php");
			
		}
		$this->display("login.php");
		
		
	}
	//验证码
	public function code()
	{
		$code = new \Hdphp\Tool\Code;
		$code->show();
		
		
	}
	//退出
	public function out()
	{
		session_unset();
		session_destroy();
		$this->success("退出成功", "index.php?c=Login&a=login");
	}
}






















